<template>
  <view class="wrap">
    <view class="top"></view>
    <view class="content">
      <view class="title">欢迎登录</view>
      <u-input
          class="u-border-bottom"
          type="number"
          v-model="tel"
          placeholder="请输入手机号"
          :clearable="true"
          @blur="validateTel"
      />
      <view class="tips" v-if="errorMessage">{{ errorMessage }}</view>
      <u-button
          @tap="submit"
          :style="inputStyle"
          class="getCaptcha"
          :disabled="!isValidTel"
      >
        获取短信验证码
      </u-button>
      <view class="alternative">
        <view class="password">密码登录</view>
        <view class="issue">遇到问题</view>
      </view>
    </view>
    <view class="buttom">
      <view class="loginType">
        <view class="wechat item">
          <view class="icon">
            <up-icon size="40" name="weixin-fill" color="rgb(83,194,64)"></up-icon>
          </view>
          微信
        </view>
        <!-- <view class="QQ item">
          <view class="icon">
            <up-icon size="40" name="qq-fill" color="rgb(17,183,233)"></up-icon>
          </view>
          QQ
        </view> -->
      </view>
      <view class="hint">
        登录代表同意
        <text class="link">用户协议、隐私政策，</text>
        并授权使用您的账号信息（如昵称、头像、收获地址）以便您统一管理
      </view>
    </view>
  </view>
</template>

<script setup>
import { computed, ref } from "vue";
import { useUView } from 'uview-plus';

const { $u } = useUView();

let tel = ref('');
let errorMessage = ref('');
let isValidTel = computed(() => $u.test.mobile(tel.value));

const validateTel = () => {
  if (!isValidTel.value) {
    errorMessage.value = '请输入有效的手机号';
  } else {
    errorMessage.value = '';
  }
};

const submit = () => {
  if (isValidTel.value) {
    $u.route({
      url: 'pages/login/code'
    });
  }
};

const inputStyle = computed(() => {
  let style = {};
  if (tel.value) {
    style.color = "#fff";
    style.backgroundColor = $u.color['warning'];
  }
  return style;
});
</script>

<style lang="scss" scoped>
.wrap {
  font-size: 28rpx;

  .content {
    width: 90%;
    margin: 80rpx auto 0;

    .title {
      text-align: center;
      font-size: 60rpx;
      font-weight: 500;
      margin-bottom: 50rpx;
    }

    .u-input {
      text-align: left;
      margin-bottom: 20rpx;
      padding-bottom: 6rpx;
    }

    .tips {
      color: $u-error;
      margin-bottom: 30rpx;
      margin-top: 8rpx;
      font-size: 24rpx;
    }

    .getCaptcha {
      background-color: $uni-img-size-base;
      color: #fff;
      border: none;
      font-size: 32rpx;
      padding: 14rpx 0;
      border-radius: 8rpx;
      width: 100%;

      &::after {
        border: none;
      }
    }

    .alternative {
      color: $u-tips-color;
      display: flex;
      justify-content: space-between;
      margin-top: 20rpx;
    }
  }

  .buttom {
    .loginType {
      display: flex;
      padding: 100rpx 50rpx 50rpx 50rpx;
      justify-content: space-between;

      .item {
        display: flex;
        flex-direction: column;
        align-items: center;
        color: $u-content-color;
        font-size: 28rpx;
      }
    }

    .hint {
      padding: 20rpx 40rpx;
      font-size: 24rpx;
      color: $u-tips-color;

      .link {
        color: $u-warning;
      }
    }
  }
}
</style>
